package cn.jinjimi.base.util;

import android.content.Context;
import android.view.Gravity;
import android.widget.Toast;


/**
 * Created by zhihui_chen on 14-8-4.
 */
public class ToastUtils {
    public static final int FAIL = 0;
    public static final int SUCCESS = 1;

    /**
     * 弹出Toast消息
     *
     * @param charSequence
     */
    public static void toastMessage(Context context, CharSequence charSequence) {
        if (context == null) return;
        Toast toast = Toast.makeText(context, charSequence, Toast.LENGTH_SHORT);
        toast.setText(charSequence);
        toast.show();
    }

    /**
     * 弹出Toast消息
     *
     * @param charSequence
     */
    public static void toastMessageMiddle(Context context, CharSequence charSequence) {
        if (context == null) return;
        Toast toast = Toast.makeText(context, charSequence, Toast.LENGTH_SHORT);
        toast.setText(charSequence);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }

    /**
     * 弹出Toast消息
     *
     * @param resId
     */
    public static void toastMessageMiddle(Context context, int resId) {
        toastMessageMiddle(context, context.getResources().getText(resId));
    }

    /**
     * 资源ID信息显示
     *
     * @param context
     * @param resId
     */
    public static void toastMessage(Context context, int resId) {
        toastMessage(context, context.getResources().getText(resId));
    }

    /**
     * 指定消息显示时间
     *
     * @param context
     * @param charSequence
     * @param time
     */
    public static void toastMessage(Context context, CharSequence charSequence, int time) {
        if (context == null) return;
        Toast toast = Toast.makeText(context, charSequence, time);
        toast.setText(charSequence);
        toast.show();
    }

}
